{extend name="common/base" /}
{block name="main"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body ">
            <div class="layui-row">
                <form class="layui-form" lay-filter="form">
                    <input type="hidden" name="id" value="{$id}">
                    <div class="layui-form-item">
                        <label  class="layui-form-label" style="text-align: left;width: 150px;">
                            主播昵称
                        </label>
                        <div class="layui-input-inline" style="font-weight: 400;line-height: 37px;">{$anchor_nickname}</div>
                    </div>
                    <div class="layui-form-item">
                        <label  class="layui-form-label" style="text-align: left;width: 150px;">
                            主播手机号
                        </label>
                        <div class="layui-input-inline" style="font-weight: 400;line-height: 37px;">{$anchor_mobile}</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="text-align: left;width: 150px;">
                            当前所在分区
                        </label>
                        <div class="layui-input-block" style="font-weight: 400;line-height: 37px;">{$partition_name}</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="text-align: left;width: 150px;">
                            当前分区主播(人)
                        </label>
                        <div class="layui-input-block" style="font-weight: 400;line-height: 37px;">{$allocation_num}</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="text-align: left;width: 160px;">
                            当前分区有效主播（人）
                        </label>
                        <div class="layui-input-block" style="font-weight: 400;line-height: 37px;">{$vip_num}</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="text-align: left;width: 150px;">分区号</label>
                        <div class="layui-input-inline">
                            <select name="partition_id">
                                <option value="">请选择迁移分区号</option>
                                {foreach $partition_list as $item }
                                     {if condition="$item['partition_id']!= $partition_id"}
                                        <option value="{$item['partition_id']}">{$item['partition_name']}（当前分区主播数：{$item['allocation_num']}人|当前分区有效主播数：{$item['vip_num']}人）</option>
                                     {/if}
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-form-mid layui-word-aux"></div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left: 20px;">
                            <button class="layui-btn" lay-submit="" lay-filter="form">开始迁移</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="alert" value="1">
{/block}
{block name="footer"}
<script>
    layui.use(['form', 'layer'],
        function() {
            let form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;
            $(document).on('click','.view_cp',function(){
                //预览
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    area: '350',
                    top:0,
                    skin: 'layui-layer-nobg', //没有背景色
                    shadeClose: true,
                    content: '<div><img style="width:100%;" src="'+$(this).attr('src')+'" /></div>'
                });
            });
            form.on('submit(form)', function(data){
                var formData = form.val('form'); // 改名避免冲突
                if($('#alert').val() == 1){
                    $('#alert').val(2);
                    $.ajax({
                        url: '/backmanage/anchor/qianYi'
                        ,data: formData // 使用新的变量名
                        ,type: 'POST'
                        ,headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                        ,success(res){
                            if(typeof res == "string"){
                                res = JSON.parse(res);
                            }
                            if (res.code == 0){
                                var index = parent.layer.getFrameIndex(window.name); // 获取当前iframe层的索引
                                parent.layer.close(index);
                                parent.layer.msg(res.msg, {icon: 1});
                                parent.layui.table.reload('table');
                            } else if($('#alert').val() == 2){
                                if(res.code == -100){
                                    console.log(-100);
                                    $('#alert').val(1);
                                }
                                layer.msg(res.msg);
                            }
                        }
                    }).fail(function(msg){
                        $('#alert').val(1);
                        layer.open({
                            content: '操作失败,请稍候再试',
                            btn: ['OK']
                        });
                    });
                }
                return false; // 阻止默认表单提交
            });    
        });
    
</script>
{/block}
